import {QueryResult} from "material-table";
import {Http} from "../Http";
import {ComponentModel} from "../../biz/model/ComponentModel";

export class ComponentApi {
    static page(projectId:string, query: any={}):Promise<QueryResult<ComponentModel>> {
        return Http.getModel<QueryResult<ComponentModel>>("/manager/rest/projects/"+projectId+"/components/page",query);
    }

    static create(projectId:string, item: ComponentModel):Promise<ComponentModel> {
        return Http.postModel<ComponentModel>("/manager/rest/projects/"+projectId+"/components/create",item);
    }

    static delete(projectId: string, item: ComponentModel):Promise<ComponentModel> {
        return Http.deleteModel<ComponentModel>("/manager/rest/projects/"+projectId+"/components/delete",{componentId: item.id});
    }

    static update(projectId: string, item: ComponentModel):Promise<ComponentModel> {
        return Http.putModel<ComponentModel>("/manager/rest/projects/"+projectId+"/components/update",item);
    }
}